<template>
  <div>
    <el-select v-model="brandId" clearable placeholder="请选择品牌" filterable>
      <el-option v-for="brand in brandOptions"
                 :key="brand.id" :label="brand.name" :value="brand.id"/>
    </el-select>
  </div>
</template>

<script>
import { getBrandSimple } from "@/api/base/brand"
export default {
  name: "SelectBrand",
  props: {
    value: {
      required: true
    }    
  },
  data() {
    return {
      brandOptions: [],
      brandId: this.value,
    }
  },
  watch: {
    value(newVal) {
      this.brandId = newVal;
    },
    brandId(newVal, oldVal){
      this.$emit("input", this.brandId)
    }
  },
  created() {
    this.getBrandListFun();
  },
  methods: {
    /** 查询品牌列表 */
    getBrandListFun(){
      getBrandSimple().then(response => {
        this.brandOptions = response.data;
      })
    },
  }
};
</script>

